#!/bin/sh

if [ "$#" -lt 2 ]; then
    echo "Usage: $0 repo_name repo_urls..."
    exit 1
fi

export ELIXIR_INSTALL=$(dirname $(dirname $(readlink -f "$0")))
. $ELIXIR_INSTALL/utils/common.sh

dir=/srv/elixir-data/$1

mkdir -p $dir/data
git clone --bare $2 $dir/repo
git config --system --add safe.directory $dir/repo

shift
shift
i=0
for remote
do
    git -C $dir/repo remote add other$i $remote
    git -C $dir/repo fetch --tags other$i
    i=$(($i+1))
done

export LXR_REPO_DIR=$dir/repo
export LXR_DATA_DIR=$dir/data
python3 /usr/local/elixir/update.py $ELIXIR_THREADS
